// JS-S00198 color 744B
#include <iostream>
#include <algorithm>
using namespace std;

constexpr int N = 2e5 + 7;
int a[N], n;
long long ans = 0;
void dfs(int idx, int b, int r, long long sum) {
    if (idx > n) {
        ans = max(ans, sum);
        return;
    }
    dfs(idx + 1, idx, r, sum + (a[idx] == a[b] ? a[idx] : 0));
    dfs(idx + 1, b, idx, sum + (a[idx] == a[r] ? a[idx] : 0));
}

int main() {
    ios::sync_with_stdio(false);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        ans = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        dfs(1, 0, 0, 0);
        cout << ans << endl;
    }
    return 0;
}
